<%-- 
    Document   : VBNoiBo.jsp
    Created on : Jun 18, 2011, 10:22:41 AM
    Author     : pdaitoan
--%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="Entity.BDoc"%>
<%@page import="java.util.List"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="Servlet.PMF"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style type="text/css">
            @import "../css/main.css";
            @import "../css/menu.css";
            @import "../menu/menu_style.css";
            @import "../css/VanBanNoiBo.css";
            @import "../css/jquery.ui.datepicker.css";
            @import "../css/jquery.ui.theme.css";
            @import "../css/demo_page.css";
            @import "../css/demo_table.css";
            .ui-widget{font-size:0.7em;}
            .ui-helper-hidden-accessible{clip:auto;}
        </style>
        <script type="text/javascript" src="../js/jquery-1.5.1.js"></script>
        <script type="text/javascript" src="../js/jquery.ui.core.js"></script>
        <script type="text/javascript" src="../js/jquery.ui.datepicker.js"></script>
        <script type="text/javascript" language="javascript" src="../js/jquery.dataTables.js"></script>
        <script type="text/javascript" src="../js/wyzz.js"></script>
        <link  type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"/>
         <script>
	$(function() {
		$( ".datepicker" ).datepicker();
	});
	</script>
        <script type="text/javascript" charset="utf-8">
		var oTable;
                var giRedraw = false;
                var ID;
		$(document).ready(function() {
			/* Add a click handler to the rows - this could be used as a callback */
			$("#example tbody").click(function(event) {
				$(oTable.fnSettings().aoData).each(function (){
					$(this.nTr).removeClass('row_selected');
				});
				$(event.target.parentNode).addClass('row_selected');
			});
				/* Add a click handler for the delete row */
			$('#delete').click( function() {
				var anSelected = fnGetSelected( oTable );
                                       //alert(anSelected[1]);
				oTable.fnDeleteRow( anSelected[0] );
			} );
				/* Init the table */
			oTable = $('#example').dataTable( {


                            "aaSorting": [[ 0, "asc" ]],
                            "sPaginationType": "full_numbers",
                            "oLanguage": {
                            "sSearch": "Search all columns:"
                            }
                        } );
                        $("tfoot input").keyup( function () {
					/* Filter on the column (the index) of this element */
					oTable.fnFilter( this.value, $("tfoot input").index(this) + 1);
			} );
                        $("tfoot input").each( function (i) {
					asInitVals[i] = this.value;
				} );

				$("tfoot input").focus( function () {
					if ( this.className == "search_init" )
					{
						this.className = "";
						this.value = "";
					}
				} );

				$("tfoot input").blur( function (i) {
					if ( this.value == "" )
					{
						this.className = "search_init";
						this.value = asInitVals[$("tfoot input").index(this)];
					}
				} );
		} );

		/* Get the rows which are currently selected */
		function fnGetSelected( oTableLocal )
		{
			var aReturn = new Array();
			var aTrs = oTableLocal.fnGetNodes();
				for ( var i=0 ; i<aTrs.length ; i++ )
			{
				if ( $(aTrs[i]).hasClass('row_selected') )
				{
					aReturn.push( aTrs[i] );
                                               ID = aTrs[i];
				}
			}

			return aReturn;
		}
                function setEdit()
                {
                      alert('Edit');
                      alert($(".row_selected .id").attr("align"));
                      var id = ID;
                      <% session.setAttribute("ID", ""); %>
                }
                function setDelete()
                {
                       alert('Delete')
                       <% session.setAttribute("ID", "Delete"); %>
                }
        </script>

        <title>JSP Page</title>
    </head>
    <body>
        <%@include file="../header.jsp" %>
        <div id="vbnb">
        	Tìm kiếm văn bản nội bộ
        </div>
        <div id="vanbandi">
        <form action="/bdoc" method="post" id="form2">
            <input type="hidden" name="action" value="search"/>
        	<table width="1141" height="120" border="0" align="center" id="tableSearch">
            <tr>
              <td width="143">&nbsp;</td>
              <td width="87" height="40">Người ký</td>
              <td width="189">
              <input type="text" name="txtSignByName" id="txtSignByName"></td>
              <td width="107">Trích yếu</td>
              <td width="448">
              <input type="text" name="txtSubject" id="txtSubject"></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td height="32">Từ ngày</td>
              <td>
                <input type="text" name="txtTuNgay" class="datepicker">
             </td>
              <td>Đến ngày</td>
              <td>
                <input type="text" name="txtDenNgay" class="datepicker">
              </td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td height="40">&nbsp;</td>
              <td colspan="3">
                <input type="submit" name="btnTim" id="button" value="Tìm kiếm"></td>
            </tr>
          </table>
          <p></p>
        </form>
        <form action="/bdoc" method="post" id="form2" action="">
            <div>
                <table width="831" height="103" border="0" cellpadding="0" cellspacing="0" class="display" id="example">
                <thead>
                  <tr>
                       <th width="58" style="width: 30px;">ID</th>
                    <th width="78" style="width: 50px;">Số VB</th>
                    <th width="178" style="width: 150px">Trích yếu</th>
                    <th width="128" style="width: 100px">Ngày ký</th>
                    <th width="86" style="width: 50px">Trạng thái</th>
                    <th width="78" style="width: 50px">Xem</th>
                    <th width="78" style="width: 50px">Sửa</th>
                    <th width="199" style="width: 50px">Xóa</th>
                  </tr>
                 </thead>
                    <tbody>
                      <%
                          PersistenceManager pm = PMF.get().getPersistenceManager();
                          List<BDoc> list = null;
                          SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
                          if (null == session.getAttribute("isSearch"))
                          {
                             String query = "select from " + BDoc.class.getName();
                             list = (List<BDoc>)pm.newQuery(query).execute();
                             //response.sendRedirect("www.null" );
                          }
                          else
                          {
                              list = (List<BDoc>)session.getAttribute("bdoc");
                              //response.sendRedirect("www.search");
                              session.setAttribute("isSearch", null);
                              session.setAttribute("bdoc", null);
                          }
                          if (list != null)
                              for(BDoc bdoc : list)
                              {
                      %>
                      <tr class="gradeA">
                        <td class="id" align="center"><% out.println(bdoc.getBDocID()); %></td>
                        <td> <% out.println(bdoc.getDocNum()); %></td>
                        <td> <% out.println(bdoc.getSubject()); %></td>
                        <td> <% out.println(df.format(bdoc.getSignDate())); %></td>
                        <td> <% out.println(bdoc.getState()); %></td>
                        <td><a href="ViewBDoc.jsp?BID=<% out.print(bdoc.getBDocID()); %>">Xem</a></td>
                        <td><a href="EditBdoc.jsp?BID=<% out.print(bdoc.getBDocID()); %>">Sửa</a></td>
                        <td><a href="DeleteBdoc.jsp?BID=<% out.print(bdoc.getBDocID()); %>">Xóa</a></td>
                      </tr>
                      <%
                                }
                            pm.close();
                      %>
                    </tbody>
                    <tfoot>
                        <tr>
                            <th></th>
                            <th><input type="text" name="search1" value="Số VB nội bộ " class="search_init" /></th>
                            <th><input type="text" name="search2" value="Trích yếu" class="search_init" /></th>
                            <th><input type="text" name="search3" value="Ngày tạo" class="search_init" /></th>
                            <th><input type="text" name="search4" value="Trạng thái" class="search_init" /></th>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>
                    </tfoot>
                </table>
          </div>
            </form>
        </div>
    </body>
</html>
